home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11680 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: kuhub.cc.ukans.edu!anh
  2. From: anh@kuhub.cc.ukans.edu
  3. Newsgroups: comp.lang.c
  4. Subject: Re: REQUEST: Recursive functions
  5. Message-ID: <1996Mar25.125041.116595@kuhub.cc.ukans.edu>
  6. Date: 25 Mar 96 12:50:41 CST
  7. References: <4h7lft$8ql@cis.clark.edu> <3150334B.1802@willows.com> <827630695snz@genesis.demon.co.uk>
  8. Organization: University of Kansas Academic Computing Services
  9.  
  10. A classic way to find one's way through a 2D maze is to always keep to the 
  11. right.  In other words, if you arrive at an intersection, turn right, 
  12. eventually you will find your way out.  Now if your maze's only exit is 
  13. the entrance you will come back to the entrance after you have visited 
  14. the whole maze, and, hence, you must have encountered the cheese on the 
  15. way.  If there are multiple exits, well, just make sure you mark the 
  16. entrance to know when to quit searching.
  17.  
  18. Recursive function calls tend to blow up the stack, unless of course, it 
  19. is tail recursion and it is guaranteed to be removed.
  20.  
  21. Now whether to implement the above algorithm with or withour recursion is 
  22. up to you.  Good luck!
  23.  
  24. Anh
  25.  
  26. In article <827630695snz@genesis.demon.co.uk>, Lawrence Kirby <fred@genesis.demon.co.uk> writes:
  27. > In article <3150334B.1802@willows.com>
  28. >            tarang@willows.com "Tarang Deshpande" writes:
  29. >>Michael Talmage wrote:
  30. >>> 
  31. >>> I need some help to write a recursive function that will move a mouse through
  32. >>> a maze to find some cheese at the end.  My instructor did not really teach us
  33. >>> how to write recursive functions in class.  Any help will be appreciated.
  34. >>> 
  35. >>
  36. >>I'm not going to tell you the answer but here is a quick leson in
  37. >>recursion.  First of all anything you do recursively can be done 
  38. >>using loops.  But using loops is more complicated and cumbersome whereas
  39. >>recursion is more elegant and simple.
  40. > In the relatively few cases that model well recursively that is true,
  41. > otherwise it is not. This is somewhat language dependent but you are
  42. > posting to comp.lang.c.
  43. >> However this does not mean that
  44. >>you should always use recusion because recursion make heavy use of the
  45. >>stack and this can cause you to run out of memory.
  46. > Even if the C language guaranteed tail-end recursion elimination you
  47. > would still write iterative loops as loops.
  48. >>What recusion does is to divide the problem into two or more parts.
  49. > It defines the problem in terms of a simpler form of itself. It must
  50. > eventually reach a point where the solution can be determined directly or
  51. > some other termination condition for it to be valid (i.e. not continue
  52. > on indefinitely).
  53. > -- 
  54. > -----------------------------------------
  55. > Lawrence Kirby | fred@genesis.demon.co.uk
  56. > Wilts, England | 70734.126@compuserve.com
  57. > -----------------------------------------
  58.